/**
 * Created by yangchen on 2017-09-13.
 */
$(document).ready(
    function () {
        var tab = new Vue({
            el: "#tab",
            methods: {
                recommend: function () {
                    window.location = 'recommend.html'
                },
                share: function () {
                    window.location = 'invitation.html'
                },
                addQQ: function () {
                    window.location = 'https://qm.qq.com/cgi-bin/qm/qr?k=8Y8YQRJYVYxYTeJBQX_vztw1ZtmykA-E#'
                },
                shareConfig: function() {
                    API.getShareConfig({
                        isWxAuth: true,
                        currentUrl: location.href
                    }).then(function(data) {
                        console.dir(data);
                         wx.config({
                            debug: false,
                            appId: data.appId,
                            timestamp: data.timestamp,
                            nonceStr: data.nonceStr,
                            signature: data.signature,
                            jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'onMenuShareQQ', 'onMenuShareQZone']
                         })
                         wx.ready(function () {

                             wx.onMenuShareAppMessage({
                                 title: "寻找财税分享达人", // 分享标题
                                 desc: '我正在参加“寻找财税分享达人”活动，有机会获得超级福利，快来帮我增加影响力吧！', // 分享描述
                                 link: data.shareUrl, // 分享链接
                                 imgUrl: './img/share_2.png' // 分享图标
                               });


                             wx.onMenuShareTimeline({
                                 title: '真心推荐 | 我正在参加“寻找财税分享达人”活动，快来帮我增加影响力吧！',
                                 link: data.shareUrl,
                                 imgUrl: './img/share_2.png'
                             });

                         });


                        wx.error(function (res) {
                            console.log('wx.error: '+JSON.stringify(res));
                        });

                    })
                }
            },
            data: {
                pageNo: 1,
                pageSize: 20,
                ranks: [],
                nickName: "",
                rankingNo: "",
                influenceNum: "",
                headImgUrl: "",
                leadersNum: "",
                presenteesNum: "",
                rankHTML1: '<svg class="icon" style="width:2em;; height: 2em;;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="947"><path d="M736 864l153.6 83.2-147.2-409.6c-6.4-19.2-32-32-51.2-25.6l-147.2 51.2c-19.2 6.4-25.6 25.6-19.2 51.2l147.2 409.6 64-160z m-448 0l64 160 147.2-409.6c12.8-25.6 0-44.8-19.2-51.2l-147.2-57.6c-19.2-6.4-38.4 6.4-44.8 25.6l-147.2 409.6 147.2-76.8z" fill="#E14B49" p-id="948"></path><path d="M512 793.6l-185.6 12.8-102.4-147.2-128-134.4 51.2-179.2 25.6-179.2 172.8-64L512 0l160 96 172.8 64 25.6 179.2 51.2 179.2-128 134.4-102.4 147.2c6.4 6.4-179.2-6.4-179.2-6.4z" fill="#F5D73E" p-id="949"></path><path d="M512 691.2c147.2 0 268.8-121.6 268.8-268.8S659.2 153.6 512 153.6 243.2 275.2 243.2 422.4c0 147.2 115.2 268.8 268.8 268.8z" fill="#E0B335" p-id="950"></path><path d="M582.4 243.2V576H492.8V358.4c-12.8 12.8-32 19.2-44.8 25.6-12.8 12.8-32 19.2-51.2 19.2V326.4c25.6-6.4 51.2-19.2 70.4-32 19.2-12.8 32-32 44.8-57.6l70.4 6.4z" fill="#F9E999" p-id="951"></path></svg>',
                rankHTML2: '<svg class="icon" style="width:2em;; height: 2em;;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="915"><path d="M681.6 1017.6l64-160 153.6 83.2L752 531.2c-6.4-19.2-32-32-51.2-25.6l-147.2 51.2c-19.2 6.4-32 32-25.6 51.2l153.6 409.6zM291.2 864l64 160 147.2-409.6c12.8-19.2 0-44.8-19.2-51.2L336 505.6c-19.2-6.4-38.4 6.4-44.8 25.6L144 940.8 291.2 864z" fill="#62C2EC" p-id="916"></path><path d="M515.2 787.2L329.6 800 227.2 646.4 99.2 512l51.2-172.8L176 153.6l172.8-64L515.2 0l160 89.6 172.8 64 25.6 185.6L924.8 512l-128 134.4L694.4 800l-179.2-12.8z" fill="#D1DFE8" p-id="917"></path><path d="M515.2 691.2c147.2 0 268.8-121.6 268.8-268.8S662.4 153.6 515.2 153.6 246.4 275.2 246.4 422.4 368 691.2 515.2 691.2z" fill="#A1B5C1" p-id="918"></path><path d="M649.6 576H374.4c0-25.6 12.8-51.2 25.6-76.8 12.8-19.2 44.8-51.2 89.6-83.2 25.6-19.2 38.4-32 51.2-44.8 6.4-12.8 12.8-19.2 12.8-32s-6.4-19.2-12.8-25.6c-12.8-6.4-19.2-12.8-32-12.8s-25.6 6.4-25.6 12.8-12.8 19.2-12.8 38.4l-96-6.4c6.4-25.6 12.8-44.8 19.2-64 6.4-19.2 25.6-25.6 44.8-38.4 19.2-6.4 44.8-12.8 70.4-12.8 25.6 0 57.6 6.4 76.8 12.8 19.2 6.4 32 19.2 44.8 32 12.8 19.2 12.8 38.4 12.8 57.6 0 19.2-6.4 38.4-19.2 57.6-12.8 19.2-32 38.4-64 64-19.2 6.4-32 19.2-38.4 25.6-6.4 0-12.8 6.4-19.2 19.2h140.8V576h6.4z" fill="#DFEBF3" p-id="919"></path></svg>',
                rankHTML3: '<svg class="icon" style="width:2em;; height: 2em;;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="979"><path d="M736 864l153.6 83.2-147.2-409.6c-6.4-19.2-32-32-51.2-25.6l-147.2 51.2c-19.2 6.4-25.6 32-19.2 51.2l147.2 409.6 64-160z m-448 0l64 160 147.2-409.6c12.8-19.2 0-44.8-19.2-51.2l-147.2-57.6c-19.2-6.4-38.4 6.4-44.8 25.6l-147.2 409.6c-6.4 0 147.2-76.8 147.2-76.8z" fill="#9B9CCD" p-id="980"></path><path d="M512 787.2l-185.6 12.8-102.4-153.6-128-134.4 51.2-172.8 25.6-185.6 172.8-64L512 0l160 89.6 172.8 64 25.6 185.6 51.2 172.8-128 134.4-102.4 153.6-179.2-12.8z" fill="#D09680" p-id="981"></path><path d="M512 691.2c147.2 0 268.8-121.6 268.8-268.8S659.2 153.6 512 153.6 243.2 275.2 243.2 422.4s121.6 268.8 268.8 268.8z" fill="#A97B6A" p-id="982"></path><path d="M467.2 364.8l-89.6-19.2c6.4-25.6 19.2-51.2 44.8-64 19.2-12.8 44.8-25.6 83.2-25.6 44.8 0 70.4 6.4 89.6 25.6 19.2 12.8 32 32 32 64 0 12.8-6.4 25.6-12.8 38.4 0 6.4-12.8 19.2-32 25.6 12.8 6.4 25.6 6.4 32 12.8 12.8 6.4 19.2 19.2 25.6 25.6 6.4 12.8 6.4 25.6 6.4 38.4 0 19.2-6.4 38.4-12.8 51.2-12.8 19.2-19.2 38.4-38.4 44.8s-44.8 19.2-76.8 19.2-51.2-6.4-70.4-12.8-25.6-19.2-38.4-32-19.2-32-25.6-51.2l89.6-12.8c6.4 19.2 6.4 32 12.8 38.4 6.4 6.4 12.8 12.8 32 12.8 12.8 0 25.6-6.4 32-12.8 6.4-12.8 12.8-19.2 12.8-32s-6.4-25.6-12.8-32c-6.4-12.8-19.2-19.2-32-19.2-6.4 0-12.8 0-32 6.4l6.4-64h12.8c12.8 0 25.6-6.4 32-12.8 6.4-6.4 12.8-12.8 12.8-25.6s-6.4-19.2-6.4-25.6c-6.4 0-19.2-6.4-25.6-6.4-12.8 0-19.2 6.4-32 12.8-6.4 6.4-19.2 12.8-19.2 32z" fill="#F3C3AA" p-id="983"></path></svg>',
                rankHTML4: '<svg class="icon" style="width: 1.2em; height: 1.5em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="709"><path d="M925.963 221.317c-0.094-5.146-0.181-9.591-0.181-13.334H779.009c2.833-62.856 1.098-111.609 1.098-111.609-0.09-2.528-2.233-4.596-4.763-4.596H521.078c-0.617 0-1.216 0.04-1.817 0.105a16.337 16.337 0 0 0-1.817-0.105H262.517c-2.529 0-4.673 2.068-4.763 4.596 0 0-1.738 48.752 1.097 111.609H112.973c-0.116 0-0.211 2.069-0.211 4.599v48.91c0 2.529 0.131 4.599 0.292 4.599 1.471 47.384 9.042 110.758 40.552 175.634 26.722 55.028 65.204 101.07 114.385 136.842 40.711 29.623 87.223 50.956 138.364 63.706 29.534 31.518 58.659 48.899 84.078 55.886v64.682c-3.625 19.217-25.67 84.284-179.33 84.284h-19.43a4.612 4.612 0 0 0-4.599 4.599v48.903a4.612 4.612 0 0 0 4.599 4.599h455.625a4.612 4.612 0 0 0 4.599-4.599v-48.901a4.612 4.612 0 0 0-4.599-4.599H727.97c-180.271 0-179.474-84.981-179.474-84.981 0.023-2.529 0.043-6.668 0.043-9.197V698.15c25.416-6.975 53.978-24.286 83.36-55.641 51.512-12.718 98.18-34.137 139.15-63.939 49.167-35.777 87.629-81.817 114.347-136.85 43-88.536 41.401-174.319 40.567-220.403zM205.842 416.329c-26.258-54.07-33.132-108.482-34.637-150.239h91.669c1.579 16.184 3.572 32.139 6.099 47.169 15.455 92.073 36.695 173.393 76.9 245.142-61.438-31.12-109.694-79.597-140.031-142.072z m627.286 0c-30.516 62.84-79.166 111.529-141.133 142.626 40.338-71.887 61.402-153.38 76.901-245.696 2.522-15.03 4.514-30.984 6.093-47.169h92.781c-1.514 41.757-8.384 96.17-34.642 150.239z" fill="#f97806" p-id="710"></path></svg>推荐奖',
                rankHTML5: '<svg class="icon" style="width: 1.2em; height: 1.5em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="920"><path d="M269.6704 949.0432c-39.2192 0-71.0144-31.3088-71.0144-69.9392 0-1.4592 0.0256-2.9184 0.128-4.352l14.336-225.5616-148.3008-179.7888a69.1712 69.1712 0 0 1 10.368-98.3552 71.4752 71.4752 0 0 1 27.8272-13.6448l224.256-54.1696 124.544-195.5328c20.8384-32.7168 64.6656-42.5984 97.8944-22.0928 9.0624 5.6064 16.7424 13.1584 22.4256 22.0928l124.5696 195.5328 224.2304 54.1696c38.0928 9.1904 61.4144 47.0528 52.0704 84.5568a68.9664 68.9664 0 0 1-13.8496 27.4432l-148.2752 179.7888 13.8752 218.496c6.3232 38.2208-19.9936 74.2144-58.8032 80.4352a69.248 69.248 0 0 1-11.2896 0.9216h-0.3584a71.7824 71.7824 0 0 1-25.3184-4.5568L512 863.0272l-217.0112 81.4336a71.7824 71.7824 0 0 1-25.3184 4.5568v0.0256z" fill="#f97806" p-id="921"></path></svg>使用奖',
                rankHTML6: '<svg class="icon" style="width: 1.2em; height: 1.5em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="949"><path d="M739.488273 191.018739c24.059057 52.988075 28.492902 142.028393-19.988643 185.203862C637.146421 64.109029 433.189579 0 433.189579 0c24.059057 161.21749-87.73197 337.044861-194.943782 468.824532-3.997729-64.109029-7.995457-109.028961-41.867121-170.085179-7.268597 116.297558-97.035775 211.879614-121.094833 328.540602-32.49063 158.455423 24.495173 274.244179 242.189665 396.720045-68.542873-142.028393-32.054514-223.50937 20.497445-300.0477a481.035775 481.035775 0 0 0 72.685974-167.17774s44.919932 58.730267 27.111868 150.459966c79.954571-89.040318 94.491766-230.196479 82.789324-284.492902 180.770017 125.964793 257.817149 398.900625 153.585463 601.040318 553.358319-312.33163 137.521863-779.775128 65.344691-832.763203z" fill="#f97806" p-id="950"></path></svg>影响力奖'

            },
            mounted() {
                this.shareConfig();
            }
        });
        weui.tab('#tab', {
            defaultIndex: 0,
            onChange: function (index) {
                if (index === 1) {
                    var nScrollHight = 0; //滚动距离总长(注意不是滚动条的长度)
                    var nScrollTop = 0;   //滚动的距离
                    var list = $("#list");
                    var nDivHight = list.height();  //div高度

                    // 节流
                    var throttle = function (func, delay) {
                        var timer;
                        return function () {
                            var context = this;
                            var args = arguments;
                            clearTimeout(timer);
                            timer = setTimeout(function () {
                                func.apply(context, args);
                            }, delay);
                        }
                    };

                    // 滚动到底部加载
                    var dealScroll = function () {
                        nScrollHight = $(this)[0].scrollHeight;
                        nScrollTop = $(this)[0].scrollTop;
                        // 滚动到底部继续加载
                        if (nScrollTop + nDivHight + 2 >= nScrollHight) {
                            tab.pageNo ++;
                            API.getInfluenceListByPage({
                                pageNo: tab.pageNo,
                                pageSize: tab.pageSize
                            }).then(function (data) {
                                data.influenceJoList.forEach(function (item, index) {
                                    tab.ranks.push(item);
                                });
                            });
                        }
                    };
                    list.scroll(throttle(dealScroll, 1000));

                    API.getLeaderInfluence().then(function (data) {
                        tab.nickName = data.nickName;
                        tab.rankingNo = data.rankingNo;
                        tab.influenceNum = data.influenceNum;
                        tab.headImgUrl = data.headImgUrl;
                    });
                    API.getInfluenceListByPage({
                        pageNo: tab.pageNo,
                        pageSize: tab.pageSize
                    }).then(function (data) {
                        tab.ranks = data.influenceJoList;
                        tab.leadersNum = data.leadersNum;
                        tab.presenteesNum = data.presenteesNum;
                    });
                }
            }
        });

    }
);